<template>
    <!-- 修改资料 -->

    <div>
        <el-form label-width="100px" :model="form" label-position="right" ref="formRef" :rules="formRules">
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="代码" prop="number">
                        <el-input v-model="form.number"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="名称" prop="name">
                        <el-input v-model="form.name"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="类别" prop="codeKind">
                        <sc-table-select v-model="codeKindRows" :apiObj="apiObj" :fileName="fileName" :table-width="700"
                            :props="tableProps" @change="change">
                        </sc-table-select>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="资源文件代码">
                        <el-input v-model="form.resourceFileNo"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="开始值" prop="startValue">
                        <el-input v-model="form.startValue"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="结束值" prop="endValue">
                        <el-input v-model="form.endValue"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="自定义1" prop="customer1">
                        <el-input v-model="form.customer1"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="自定义2" prop="customer2">
                        <el-input v-model="form.customer2"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="自定义3" prop="customer3">
                        <el-input v-model="form.customer3"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="自定义4" prop="customer4">
                        <el-input v-model="form.customer4"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="自定义5" prop="customer5">
                        <el-input v-model="form.customer5"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="自定义6" prop="customer6">
                        <el-input v-model="form.customer6"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="自定义7" prop="customer7">
                        <el-input v-model="form.customer7"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="自定义8" prop="customer8">
                        <el-input v-model="form.customer8"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
                <el-form-item label="状态" prop="status">
                    <el-switch v-model="form.status" size="large" inline-prompt :active-icon="Check" :inactive-icon="Close"
                        active-value="normal" inactive-value="disable" />
                </el-form-item>
                    <el-form-item label="备注">
                        <el-input v-model="form.remark" type="textarea"></el-input>
                    </el-form-item>

        </el-form>
        <div class="button-position">
            <el-button @click="updateVisible">取 消</el-button>
            <el-button type="primary" @click="addcodekind(formRef)">确 定</el-button>
        </div>
    </div>
</template>

<script setup>
import { reactive, ref, getCurrentInstance, watch, onMounted } from 'vue';
import { ElNotification } from 'element-plus';
import { Check, Close } from '@element-plus/icons-vue';
import Api from '@/api/model/system'

const emit = defineEmits(['updatetable'])

const props = defineProps({
    paramsData: {
        type: Object,
        defalut: {}
    }
})
const apiObj = ref(Api.select.query)
const fileName = ref('CodeKindReport')
const tableProps = {
    label: 'name',
    value: 'id',
}
const codeKindRows = ref({})


// 添加用户数据的对象
const form = ref({
});

const formRef = ref()
const formRules = reactive({
    // name: [
    //       { required: true, message: "请输入名称", trigger: "blur" },
    //     ],
    // codeKind: [
    //       { required: true, message: "请输入类别", trigger: "blur" },
    //     ],
})
onMounted(() => {
    getInit()
})
const getInit = async () => {
    let res = await Api.syscode.add.post()
    if (res.code == '200') {
        form.value = res.data
    }
}
const change = (val) => {
    form.value.codeKind = val.id
}

const restAddFormData = () => {
    formRef.value.resetFields();
}

const updateVisible = () => {
    emit('updatetable')
}


// 上传
const addcodekind = async (formRef) => {
    await formRef.validate((valid, fields) => {
        if (valid) {
            addsyscodeData();

        }
    })
}

const addsyscodeData = async () => {
    var params = {
        bean: form.value,
    }
    var res = await Api.syscode.save.post(params);
    if (res.code == 200) {
        restAddFormData()
        ElNotification.success({ title: '', message: '添加成功！', duration: 2000 });
        emit('updatetable', true)
    }
}

</script>

<style lang="less" scoped></style>

